Skip to content

fix(telegram): skip empty text in sendMessageDraft to prevent 400 spam#7398

Open
he-yufeng wants to merge 1 commit intoAstrBotDevs:masterfrom
he-yufeng:fix/telegram-empty-draft
Open

fix(telegram): skip empty text in sendMessageDraft to prevent 400 spam#7398
he-yufeng wants to merge 1 commit intoAstrBotDevs:masterfrom
he-yufeng:fix/telegram-empty-draft

Conversation

@he-yufeng
Copy link
Copy Markdown
Contributor

@he-yufeng he-yufeng commented Apr 6, 2026

Summary

Fixes #7353

When streaming output is enabled, markdownify() can return empty strings for certain inputs (whitespace-only content, formatting-only markdown). The draft sender loop then calls sendMessageDraft with empty text, which Telegram rejects with "Text must be non-empty", flooding the log every 0.5s.

Changes

Added an early return in _send_message_draft() when text is empty or whitespace-only. This matches WebChat's approach of skipping empty responses (webchat_event.py line 200: if not r: continue).

Test plan

  • Enable streaming output, send a message in Telegram private chat
  • Verify no more "sendMessageDraft failed: Text must be non-empty" warnings in log
  • Verify streaming output still displays correctly for normal messages

Summary by Sourcery

Bug Fixes:

  • Prevent Telegram sendMessageDraft calls with empty text that result in repeated 400 errors and log spam during streaming output.

When streaming is enabled, markdownify() can produce empty strings for
certain inputs (whitespace-only, formatting-only markdown). The draft
sender loop then calls sendMessageDraft with empty text, which Telegram
rejects with 'Text must be non-empty', flooding the log every 0.5s.

Add an early return in _send_message_draft() when text is empty or
whitespace-only. This matches WebChat's approach of skipping empty
responses.

Fixes AstrBotDevs#7353
@dosubot dosubot bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Apr 6, 2026
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • Consider updating the _send_message_draft docstring (and any type hints) to explicitly document that empty/whitespace-only text is ignored and that the function may return early without sending anything.
  • If text can be something other than str (e.g., None or other falsy value), you may want to narrow the condition to a string check to avoid accidentally skipping non-string payloads that should be handled differently.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider updating the `_send_message_draft` docstring (and any type hints) to explicitly document that empty/whitespace-only text is ignored and that the function may return early without sending anything.
- If `text` can be something other than `str` (e.g., `None` or other falsy value), you may want to narrow the condition to a string check to avoid accidentally skipping non-string payloads that should be handled differently.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@dosubot dosubot bot added the area:platform The bug / feature is about IM platform adapter, such as QQ, Lark, Telegram, WebChat and so on. label Apr 6, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a guard clause in the _send_message_draft method within the Telegram platform source to prevent the processing of empty or whitespace-only messages. I have no feedback to provide as the implementation is correct and there were no review comments to evaluate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:platform The bug / feature is about IM platform adapter, such as QQ, Lark, Telegram, WebChat and so on. size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Telegram 私聊流式输出失败:sendMessageDraft Text must be non-empty

1 participant